package net.toocruel.yarn.mapreduce.wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author : 宋同煜
 * @version : 1.0
 * @createTime : 2017/4/12 14:16
 * @description :
 */
public class WordCountReducer extends Reducer<Text,IntWritable,Text,IntWritable>{

    //存取对应单词总频数
    private IntWritable result = new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        //计算频数
        int sum = 0;
        for(IntWritable value:values){
            sum+=value.get();
        }
        result.set(sum);
        //写入输出
        context.write(key, result);
    }
}
